﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.EquipmentManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.EquipmentManagement.EquipAlarmRecordVMs
{
    public partial class EquipAlarmRecordListVM : BasePagedListVM<EquipAlarmRecord_View, EquipAlarmRecordSearcher>
    {
        
        protected override IEnumerable<IGridColumn<EquipAlarmRecord_View>> InitGridHeader()
        {
            return new List<GridColumn<EquipAlarmRecord_View>>{
                
                this.MakeGridHeader(x => x.EquipAlarmRecord_ProductId).SetTitle(@Localizer["Page.产品号"].Value),
                this.MakeGridHeader(x => x.EquipAlarmRecord_Equipment).SetTitle(@Localizer["Page.设备"].Value),
                this.MakeGridHeader(x => x.EquipAlarmRecord_EquipCode).SetTitle(@Localizer["Page.设备编号"].Value),
                this.MakeGridHeader(x => x.EquipAlarmRecord_EquipName).SetTitle(@Localizer["Page.设备名称"].Value),
                this.MakeGridHeader(x => x.EquipAlarmRecord_OpCode).SetTitle(@Localizer["Page.工位"].Value),
                this.MakeGridHeader(x => x.EquipAlarmRecord_Address).SetTitle(@Localizer["Page.报警地址"].Value),
                this.MakeGridHeader(x => x.EquipAlarmRecord_Bits).SetTitle(@Localizer["Page.位"].Value),
                this.MakeGridHeader(x => x.EquipAlarmRecord_Content).SetTitle(@Localizer["Page.报警内容"].Value),
                this.MakeGridHeader(x => x.EquipAlarmRecord_Level).SetTitle(@Localizer["Page.报警级别"].Value),
                this.MakeGridHeader(x => x.EquipAlarmRecord_Classify).SetTitle(@Localizer["Page.报警分类"].Value),
                this.MakeGridHeader(x => x.EquipAlarmRecord_Duration).SetTitle(@Localizer["Page.警报时长"].Value),
                this.MakeGridHeader(x => x.EquipAlarmRecord_Status).SetTitle(@Localizer["Page.报警状态"].Value),
                this.MakeGridHeader(x => x.EquipAlarmRecord_StartTime).SetTitle(@Localizer["Page.开始时间"].Value),
                this.MakeGridHeader(x => x.EquipAlarmRecord_EndTime).SetTitle(@Localizer["Page.结束时间"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<EquipAlarmRecord_View> GetSearchQuery()
        {
            var query = DC.Set<EquipmentAlarmRecord>()
                
                .CheckEqual(Searcher.ProductId, x=>x.ProductId)
                .CheckEqual(Searcher.EquipmentId, x=>x.EquipmentId)
                .CheckContain(Searcher.EquipCode, x=>x.EquipCode)
                .CheckContain(Searcher.EquipName, x=>x.EquipName)
                .CheckContain(Searcher.OpCode, x=>x.OpCode)
                .CheckContain(Searcher.Address, x=>x.Address)
                .CheckEqual(Searcher.Bits, x=>x.Bits)
                .CheckContain(Searcher.Content, x=>x.Content)
                .CheckEqual(Searcher.Level, x=>x.Level)
                .CheckEqual(Searcher.Classify, x=>x.Classify)
                .CheckEqual(Searcher.Duration, x=>x.Duration)
                .CheckEqual(Searcher.Status, x=>x.Status)
                .CheckBetween(Searcher.StartTime?.GetStartTime(), Searcher.StartTime?.GetEndTime(), x => x.StartTime, includeMax: false)
                .CheckBetween(Searcher.EndTime?.GetStartTime(), Searcher.EndTime?.GetEndTime(), x => x.EndTime, includeMax: false)
                .Select(x => new EquipAlarmRecord_View
                {
				    ID = x.ID,
                    
                    EquipAlarmRecord_ProductId = x.ProductId,
                    EquipAlarmRecord_Equipment = x.Equipment.TenantCode,
                    EquipAlarmRecord_EquipCode = x.EquipCode,
                    EquipAlarmRecord_EquipName = x.EquipName,
                    EquipAlarmRecord_OpCode = x.OpCode,
                    EquipAlarmRecord_Address = x.Address,
                    EquipAlarmRecord_Bits = x.Bits,
                    EquipAlarmRecord_Content = x.Content,
                    EquipAlarmRecord_Level = x.Level,
                    EquipAlarmRecord_Classify = x.Classify,
                    EquipAlarmRecord_Duration = x.Duration,
                    EquipAlarmRecord_Status = x.Status,
                    EquipAlarmRecord_StartTime = x.StartTime,
                    EquipAlarmRecord_EndTime = x.EndTime,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class EquipAlarmRecord_View: EquipmentAlarmRecord
    {
        
        public long? EquipAlarmRecord_ProductId { get; set; }
        public string EquipAlarmRecord_Equipment { get; set; }
        public string EquipAlarmRecord_EquipCode { get; set; }
        public string EquipAlarmRecord_EquipName { get; set; }
        public string EquipAlarmRecord_OpCode { get; set; }
        public string EquipAlarmRecord_Address { get; set; }
        public int? EquipAlarmRecord_Bits { get; set; }
        public string EquipAlarmRecord_Content { get; set; }
        public AlarmLevelEnum? EquipAlarmRecord_Level { get; set; }
        public AlarmTypeEnum? EquipAlarmRecord_Classify { get; set; }
        public decimal? EquipAlarmRecord_Duration { get; set; }
        public AlarmStatusEnum? EquipAlarmRecord_Status { get; set; }
        public DateTime? EquipAlarmRecord_StartTime { get; set; }
        public DateTime? EquipAlarmRecord_EndTime { get; set; }

    }

}